const path = require('path')
const transformCode = require('../src/babel-test')

module.exports = function (source) {
  const basename = path.basename(this.resourcePath);
  const dirname = path.dirname(this.resourcePath)
  var fileName = path.join(path.basename(dirname),basename)// 获取文件名
  var sourceMatch = source.match(/([\s\S]*)<script>([\s\S]*)<\/script>([\s\S]*)/i);
  var {code} = transformCode(sourceMatch[2],{
      created:['created',fileName],
      mounted:['mounted',fileName]
    })
  source=source.replace(/<script>([\s\S]*)<\/script>/i,`<script>${code}</script>`)
  console.log(source,'source');
  return `module.exports = ${source}`
}